/**
 * 
 */
package com.wm.service.imp;

import java.util.List;

import com.wm.bean.Area;
import com.wm.bean.City;
import com.wm.dao.AreaDAO;
import com.wm.dao.CityDAO;
import com.wm.service.AreaService;
import com.wm.service.CityService;
import com.wm.service.web.PageList;
import com.wm.service.web.Pages;

/**
 * @author zhangbaochao
 *
 */
public class AreaServiceImp implements AreaService {
	
	private AreaDAO areaDAO;
	
	public AreaDAO getAreaDAO() {
		return areaDAO;
	}

	public void setAreaDAO(AreaDAO areaDAO) {
		this.areaDAO = areaDAO;
	}

	/**
	 * 保存Area对象
	 * 
	 * @param area
	 * 			Area
	 * @return Area
	 * 			Area
	 */
	public Area saveArea(Area area){
		return this.getAreaDAO().saveArea(area);
	}
	
	/**
	 * 更新Area对象
	 * 
	 * @param area
	 * 			Area
	 * @return Area
	 * 			Area
	 */
	public Area updateArea(Area area){
		return this.getAreaDAO().updateArea(area);
	}
	
	/**
	 * 根据ID删除Area对象
	 * 
	 * @param id
	 * 			long
	 */
	public void removeAreaById(long id){
		this.getAreaDAO().removeAreaById(id);
	}
	
	/**
	 * 根据ID获取Area对象
	 * 
	 * @param id
	 * 			long
	 * @return Area
	 * 			Area
	 */
	public Area findAreaByid(long id){
		return this.getAreaDAO().findAreaByid(id);
	}
	
	/**
	 * 根据参数获取Area对象列表
	 * 
	 * @param cityId
	 * 			long
	 * @param isShow
	 * 			int
	 * @param orderby
	 * @param ascOrDesc
	 * @return List
	 * 			List
	 */
	public List findAreasByCityIdIsShow(long cityId,int isShow, String orderby, int ascOrDesc){
		return this.getAreaDAO().findAreasByCityIdIsShow(cityId, isShow, orderby, ascOrDesc);
	}
	
	/**
	 /**
	 * 根据参数获取Area对象列表
	 * 
	 * @param isShow
	 * 			int
	 * @param orderby
	 * @param ascOrDesc
	 * @param pages
	 * @return PageList
	 * 			PageList
	 */
	public PageList findAreasByCityIdIsShow(long cityId,int isShow,String orderby,int ascOrDesc,Pages pages){
		PageList pl = new PageList();
        if (pages.getTotalNum() == -1) {
            pages.setTotalNum(this.getAreaDAO().getAreaNumByCityIdIsShow(cityId, isShow));
        }
        pages.executeCount();
        if(pages.getTotalNum() == 0){
        	pl.setObjectList(null);
        	pl.setPages(pages);
        	return pl;
        }
        List l = this.getAreaDAO().findAreasByCityIdIsShow(cityId,isShow, orderby, ascOrDesc, pages.getSpage(), pages.getPerPageNum());
        if(l == null || l.isEmpty()){
	   		 pl.setObjectList(null);
	   	     pl.setPages(pages);
	   		 return pl;
		}else{
			pl.setObjectList(l);
	        pl.setPages(pages);
	        return pl;
		}  
	}
	/**
	 * 根据参数获取Area对象列表
	 * 
	 * @param isShow
	 * 			int
	 * @param orderby
	 * @param ascOrDesc
	 * @return List
	 * 			List
	 */
	public List findAreasByIsShow(int isShow,String orderby,int ascOrDesc){
		return this.getAreaDAO().findAreasByIsShow(isShow, orderby, ascOrDesc);
	}

}
